<?php

namespace App\Admin\Controllers\Log;

use App\Http\Controllers\Controller;
use App\Model\Log\RongcloudResults;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Form;
use Encore\Admin\Controllers\ModelForm;
use Encore\Admin\Layout\Content;
use App\Util\ComUtil;
class RongcloudResultsController extends Controller
{
    use ModelForm;

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {

        return Admin::content(function (Content $content) {
            $content->header('融云审核回调记录');
            $content->description('');
            $content->body($this->grid());
        });
    }


    protected function grid()
    {

        $grid = new Grid(new RongcloudResults());
        $grid->fixColumns(3, -2);
        $grid->model()->with('eventUser')->with('eventToUser')->orderBy('id', 'desc');
        $grid->id('ID');
        $grid->created_at('发送时间');
        $grid->from_user_id('发送者')->display(function (){
            $str  = '内部ID：'.$this->from_user_id."<br/>";
            $str .= '昵称：' .$this->eventUser->nick_name;
            return $str;
        });
        $grid->to_user_id('接收者')->display(function (){
            $str  = '内部ID：'.$this->to_user_id."<br/>";
            $str .= '昵称：' .$this->eventToUser->nick_name;
            return $str;
        });
        $grid->risk_description('风险原因');
        $grid->msg_type('消息类型')->display(function (){
            return RongcloudResults::MSG_TYPE[$this->msg_type];
        });
        $grid->content('消息内容')->display(function (){
            switch ($this->msg_type){
                case RongcloudResults::RONG_TEXT_TYPE:
                    return $this->content;
                case RongcloudResults::RONG_SOUND_TYPE:
                    return ComUtil::buildAudio($this->content);
                case RongcloudResults::RONG_IMG_TYPE:
                    return ComUtil::buidlImgaeHtml($this->content);
            }
        });

        $grid->risk_level('等级')->display(function (){
            return empty(RongcloudResults::RISK_LEVEL[$this->risk_level]) ? '' : RongcloudResults::RISK_LEVEL[$this->risk_level];
        });

        $grid->msg_uid('融云消息ID');
        $grid->filter(function($filter){
            $filter->disableIdFilter();
            $filter->equal('from_user_id', '用户ID');
            $filter->equal('eventUser.nick_name', '用户昵称');
        });

        // 全部关闭
        $grid->disableActions();
        return $grid;
    }




}
